//
//  XQHomeBigAboutView.m
//  JoinPeso
//
//  Created by 小琦 on 2024/11/19.
//

#import "XQHomeBigAboutView.h"
#import "XQHomeBigAboutCell.h"

@interface XQHomeBigAboutView()<UICollectionViewDelegateFlowLayout,UICollectionViewDataSource>
@property (nonatomic,copy) NSArray *images;
@property (nonatomic,strong) UILabel *aboutLb;
@property (nonatomic,strong) UIButton *moreBtn;
@property (nonatomic,strong) UICollectionView *collectionView;
@end

@implementation XQHomeBigAboutView

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self initData];
        [self makeUI];
        [self makeConstraints];
    }
    return self;
}

- (void)initData {
    self.images = @[@"home_about1",@"home_about2",@"home_about3"];
}

- (void)makeUI {
    [self addSubview:self.aboutLb];
    [self addSubview:self.moreBtn];
    [self addSubview:self.collectionView];
}

- (void)makeConstraints {
    [self.aboutLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(@0);
        make.left.equalTo(@16);
    }];
    [self.moreBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(@-16);
        make.centerY.equalTo(self.aboutLb);
    }];
    [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.aboutLb.mas_bottom).offset(10);
        make.left.right.equalTo(@0);
        make.height.mas_equalTo(68);
        make.bottom.equalTo(@0);
    }];
}

#pragma mark - UICollectionViewDelegateFlowLayout,UICollectionViewDataSource

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return self.images.count;
}

- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    XQHomeBigAboutCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"XQHomeBigAboutCell" forIndexPath:indexPath];
    [cell setImageName:self.images[indexPath.item]];
    return cell;
}

#pragma mark - private

- (void)moreClick {
    if (self.moreHandle) {
        self.moreHandle();
    }
}

#pragma mark - lazy

- (UILabel *)aboutLb {
    if (!_aboutLb) {
        _aboutLb = [[UILabel alloc] init];
        _aboutLb.text = @"About Us";
        _aboutLb.textColor = [UIColor colorWithHexString:@"#0E1D31"];
        _aboutLb.font = [UIFont boldSystemFontOfSize:16];
    }
    return  _aboutLb;
}

- (UIButton *)moreBtn {
    if (!_moreBtn) {
        _moreBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _moreBtn.hidden = YES;
        [_moreBtn setImage:[UIImage imageNamed:@"about_more"] forState:UIControlStateNormal];
        [_moreBtn addTarget:self action:@selector(moreClick) forControlEvents:UIControlEventTouchUpInside];
    }
    return _moreBtn;
}


- (UICollectionView *)collectionView {
    if (!_collectionView) {
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
        layout.minimumLineSpacing = 8;
        layout.minimumInteritemSpacing = 8;
        layout.sectionInset = UIEdgeInsetsZero;
        layout.itemSize = CGSizeMake(145, 68);
        layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
       _collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
        _collectionView.backgroundColor = [UIColor clearColor];
        [_collectionView setContentInset:UIEdgeInsetsMake(0, 16, 0, 16)];
        _collectionView.dataSource = self;
        _collectionView.delegate = self;
        _collectionView.automaticallyAdjustsScrollIndicatorInsets = NO;
        _collectionView.showsVerticalScrollIndicator = NO;
        _collectionView.showsHorizontalScrollIndicator = NO;
        _collectionView.translatesAutoresizingMaskIntoConstraints = NO;
        [_collectionView registerClass:[XQHomeBigAboutCell class] forCellWithReuseIdentifier:@"XQHomeBigAboutCell"];
    }
    return  _collectionView;
}

@end
